package com.jaya.budan.activity;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.RequiresApi;

import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.google.gson.Gson;
import com.jaya.budan.R;
import com.jaya.budan.base.BaseActivity;
import com.jaya.budan.bean.User_Information;
import com.jaya.budan.bean.User_Limit;
import com.jaya.budan.connect.RequestConnect;
import com.jaya.budan.utils.ToolUtils;
import com.jaya.budan.utils.VolleyUtil;
import com.jaya.budan.views.Circle_ImageView;
import com.jaya.budan.views.CommonPopWindow;
import com.jaya.budan.views.CustomDatePicker;
import com.jaya.budan.views.PickerScrollView;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Set;

public class GeRen_Update_Msg_Activity extends BaseActivity implements View.OnClickListener, CommonPopWindow.ViewClickListener {

    private RelativeLayout back, rl_geren_main_update_msg_gxqm, rl_geren_main_update_msg_name, rl_geren_main_update_msg_born, rl_geren_main_update_msg_photo,
            rl_geren_main_update_msg_height, rl_geren_main_update_msg_juese, rl_geren_main_update_msg_tixing, rl_geren_main_update_msg_home,
            rl_geren_main_update_msg_sflb, rl_geren_main_update_msg_jymd, rl_geren_main_update_msg_work, rl_geren_main_update_msg_gqzk,
            rl_geren_main_update_msg_gxtd, rl_geren_main_update_msg_like_tixing, rl_geren_main_update_msg_like_style;
    private String access_token, now, time_bron = "1990-01-01", height = "170cm", weight = "65kg", path, nickname;
    private Set<String> i_face, i_style, aim, style;
    private CustomDatePicker customDatePicker;
    private Circle_ImageView iv_geren_update_msg_icon;
    private TextView tv_fill_bron, tv_geren_main_update_msg_height, tv_geren_main_update_msg_juese, tv_geren_main_update_msg_tixing, tv_geren_main_update_complete, tv_feedback_tijiao, tv_geren_main_update_msg_gxqm,
            tv_geren_main_update_msg_aim, tv_geren_main_msg_work, tv_geren_main_msg_style, tv_geren_main_gqzk, tv_geren_main_msg_sflb, tv_geren_main_msg_tixing, tv_geren_main_msg_like_style, tv_about_us_code, tv_geren_main_home;
    private LinearLayout ll_geren_main_update_msg_icon;
    private User_Information user_information;
    private User_Limit user_limit;
    private View view;
    @SuppressLint("SetTextI18n")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        view = View.inflate(this, R.layout.activity_geren_main_update_msg, null);
        setContentView(R.layout.activity_geren_main_update_msg);
        Intent intent = getIntent();
        access_token = intent.getStringExtra("access_token");
        user_limit = (User_Limit) intent.getSerializableExtra("user_limit");
        back = findViewById(R.id.back);
        rl_geren_main_update_msg_gxqm = findViewById(R.id.rl_geren_main_update_msg_gxqm);
        rl_geren_main_update_msg_name = findViewById(R.id.rl_geren_main_update_msg_name);
        rl_geren_main_update_msg_born = findViewById(R.id.rl_geren_main_update_msg_born);
        rl_geren_main_update_msg_height = findViewById(R.id.rl_geren_main_update_msg_height);
        rl_geren_main_update_msg_juese = findViewById(R.id.rl_geren_main_update_msg_juese);
        rl_geren_main_update_msg_tixing = findViewById(R.id.rl_geren_main_update_msg_tixing);
        rl_geren_main_update_msg_home = findViewById(R.id.rl_geren_main_update_msg_home);
        rl_geren_main_update_msg_sflb = findViewById(R.id.rl_geren_main_update_msg_sflb);
        rl_geren_main_update_msg_jymd = findViewById(R.id.rl_geren_main_update_msg_jymd);
        rl_geren_main_update_msg_work = findViewById(R.id.rl_geren_main_update_msg_work);
        rl_geren_main_update_msg_gqzk = findViewById(R.id.rl_geren_main_update_msg_gqzk);
        rl_geren_main_update_msg_photo = findViewById(R.id.rl_geren_main_update_msg_photo);
        rl_geren_main_update_msg_gxtd = findViewById(R.id.rl_geren_main_update_msg_gxtd);
        rl_geren_main_update_msg_like_tixing = findViewById(R.id.rl_geren_main_update_msg_like_tixing);
        rl_geren_main_update_msg_like_style = findViewById(R.id.rl_geren_main_update_msg_like_style);
        ll_geren_main_update_msg_icon = findViewById(R.id.ll_geren_main_update_msg_icon);
        iv_geren_update_msg_icon = findViewById(R.id.iv_geren_update_msg_icon);
        tv_fill_bron = findViewById(R.id.tv_fill_bron);
        tv_about_us_code = findViewById(R.id.tv_about_us_code);
        tv_geren_main_update_msg_gxqm = findViewById(R.id.tv_geren_main_update_msg_gxqm);
        tv_geren_main_update_msg_height = findViewById(R.id.tv_geren_main_update_msg_height);
        tv_geren_main_update_msg_juese = findViewById(R.id.tv_geren_main_update_msg_juese);
        tv_geren_main_update_msg_tixing = findViewById(R.id.tv_geren_main_update_msg_tixing);
        tv_geren_main_update_complete = findViewById(R.id.tv_geren_main_update_complete);
        tv_geren_main_update_msg_aim = findViewById(R.id.tv_geren_main_update_msg_aim);
        tv_geren_main_msg_work = findViewById(R.id.tv_geren_main_msg_work);
        tv_geren_main_msg_style = findViewById(R.id.tv_geren_main_msg_style);
        tv_geren_main_gqzk = findViewById(R.id.tv_geren_main_gqzk);
        tv_geren_main_home = findViewById(R.id.tv_geren_main_home);
        tv_geren_main_msg_sflb = findViewById(R.id.tv_geren_main_msg_sflb);
        tv_geren_main_msg_tixing = findViewById(R.id.tv_geren_main_msg_tixing);
        tv_geren_main_msg_like_style = findViewById(R.id.tv_geren_main_msg_like_style);
        tv_feedback_tijiao = findViewById(R.id.tv_feedback_tijiao);
        back.setOnClickListener(this);
        rl_geren_main_update_msg_gxqm.setOnClickListener(this);
        rl_geren_main_update_msg_name.setOnClickListener(this);
        rl_geren_main_update_msg_born.setOnClickListener(this);
        rl_geren_main_update_msg_height.setOnClickListener(this);
        rl_geren_main_update_msg_juese.setOnClickListener(this);
        rl_geren_main_update_msg_tixing.setOnClickListener(this);
        rl_geren_main_update_msg_home.setOnClickListener(this);
        rl_geren_main_update_msg_sflb.setOnClickListener(this);
        rl_geren_main_update_msg_jymd.setOnClickListener(this);
        rl_geren_main_update_msg_work.setOnClickListener(this);
        rl_geren_main_update_msg_gqzk.setOnClickListener(this);
        rl_geren_main_update_msg_photo.setOnClickListener(this);
        rl_geren_main_update_msg_gxtd.setOnClickListener(this);
        rl_geren_main_update_msg_like_tixing.setOnClickListener(this);
        rl_geren_main_update_msg_like_style.setOnClickListener(this);
        ll_geren_main_update_msg_icon.setOnClickListener(this);
        tv_feedback_tijiao.setOnClickListener(this);
        Glide.with(GeRen_Update_Msg_Activity.this).load(user_limit.getHead()).apply(new RequestOptions()
                .placeholder(R.mipmap.fill_person_icon).error(R.mipmap.fill_person_icon)
                .diskCacheStrategy(DiskCacheStrategy.NONE)//关闭Glide的硬盘缓存机制
        ).into(iv_geren_update_msg_icon);
        tv_geren_main_update_complete.setText("完成度" + user_limit.getComplete() + "");
        tv_geren_main_update_msg_gxqm.setText("" + user_limit.getRemark());
        tv_about_us_code.setText("" + user_limit.getNicename());
        tv_fill_bron.setText("" + user_limit.getBirthday());
        tv_geren_main_update_msg_height.setText(user_limit.getHeight() + "/" + user_limit.getWeigh());
        postData();
        initData();
    }

    @SuppressLint("NonConstantResourceId")
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.rl_geren_main_update_msg_gxqm:
                Intent intent = new Intent(this, GeRen_Update_Msg_GXQM_Activity.class);
                intent.putExtra("access_token", access_token);
                intent.putExtra("user_limit", user_limit);
                startActivity(intent);
                break;
            case R.id.rl_geren_main_update_msg_born:
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.CHINA);
                now = sdf.format(new Date());//获取当前时间
                //tvElectricalTime.setText(now.split(" ")[0]);
                customDatePicker = new CustomDatePicker(this, new CustomDatePicker.ResultHandler() {
                    @SuppressLint("SetTextI18n")
                    @Override
                    public void handle(String time) { // 回调接口，获得选中的时间
                        time_bron = time.substring(0, 10);
                        Log.d("yyyyy", time_bron);
                        tv_fill_bron.setVisibility(View.VISIBLE);
                        tv_fill_bron.setText("" + time_bron);
                    }
                }, "1960-01-01 00:00", now); // 初始化日期格式请用：yyyy-MM-dd HH:mm，否则不能正常运行
                customDatePicker.showSpecificTime(false); // 不显示时和分
                customDatePicker.setIsLoop(false); // 不允许循环滚动
                customDatePicker.show(now);//显示当前时间
                break;
            case R.id.rl_geren_main_update_msg_name:
                CommonPopWindow.newBuilder()
                        .setView(R.layout.pop_geren_update_msg_name)
                        .setAnimationStyle(R.style.AnimUp)
                        .setBackgroundDrawable(new BitmapDrawable())
                        .setSize(0, 600)
                        .setViewOnClickListener(this)
                        .setBackgroundDarkEnable(true)
                        .setBackgroundAlpha(0.7f)
                        .build(this)
                        .showAsCenter(v);
                break;
            case R.id.rl_geren_main_update_msg_height:
                CommonPopWindow.newBuilder()
                        .setView(R.layout.pop_picker_selector_bottom)
                        .setAnimationStyle(R.style.AnimUp)
                        .setBackgroundDrawable(new BitmapDrawable())
                        .setSize(0, 600)
                        .setViewOnClickListener(this)
                        .setBackgroundDarkEnable(true)
                        .setBackgroundAlpha(0.7f)
                        .build(this)
                        .showAsCenter(v);
                break;
            case R.id.rl_geren_main_update_msg_juese:
                Intent intent11 = new Intent(this, GeRen_Update_Msg_Gxtd_Activity.class);
                intent11.putExtra("access_token", access_token);
                intent11.putExtra("user_information", user_information);
                intent11.putExtra("type", 0);
                startActivity(intent11);
                break;
            case R.id.rl_geren_main_update_msg_tixing:
                Intent intent12 = new Intent(this, GeRen_Update_Msg_Gxtd_Activity.class);
                intent12.putExtra("access_token", access_token);
                intent12.putExtra("user_information", user_information);
                intent12.putExtra("type", 0);
                startActivity(intent12);
                break;
            case R.id.rl_geren_main_update_msg_home:
                Intent intent1 = new Intent(this, GeRen_Update_Msg_Home_Activity.class);
                intent1.putExtra("access_token", access_token);
                startActivity(intent1);
                break;
            case R.id.rl_geren_main_update_msg_sflb:
                Intent intent2 = new Intent(this, GeRen_Update_Msg_Sflb_Activity.class);
                intent2.putExtra("access_token", access_token);
                intent2.putExtra("user_information", user_information);
                startActivity(intent2);
                break;
            case R.id.rl_geren_main_update_msg_jymd:
                Intent intent3 = new Intent(this, GeRen_Update_Msg_Gxtd_Activity.class);
                intent3.putExtra("access_token", access_token);
                intent3.putExtra("user_information", user_information);
                intent3.putExtra("type", 2);
                startActivity(intent3);
                break;
            case R.id.rl_geren_main_update_msg_gqzk:
                Intent intent10 = new Intent(this, GeRen_Update_Msg_Gxtd_Activity.class);
                intent10.putExtra("access_token", access_token);
                intent10.putExtra("user_information", user_information);
                intent10.putExtra("type", 2);
                startActivity(intent10);
                break;
            case R.id.rl_geren_main_update_msg_gxtd:
                Intent intent4 = new Intent(this, GeRen_Update_Msg_Gxtd_Activity.class);
                intent4.putExtra("access_token", access_token);
                intent4.putExtra("user_information", user_information);
                intent4.putExtra("type", 1);
                startActivity(intent4);
                break;
            case R.id.rl_geren_main_update_msg_work:
                Intent intent5 = new Intent(this, GeRen_Update_Msg_Work_Activity.class);
                intent5.putExtra("access_token", access_token);
                intent5.putExtra("user_information", user_information);
                startActivity(intent5);
                break;
            case R.id.rl_geren_main_update_msg_like_tixing:
                Intent intent8 = new Intent(this, GeRen_Update_Msg_Gxtd_Activity.class);
                intent8.putExtra("access_token", access_token);
                intent8.putExtra("user_information", user_information);
                intent8.putExtra("type", 3);
                startActivity(intent8);
                break;
            case R.id.rl_geren_main_update_msg_like_style:
                Intent intent9 = new Intent(this, GeRen_Update_Msg_Gxtd_Activity.class);
                intent9.putExtra("access_token", access_token);
                intent9.putExtra("user_information", user_information);
                intent9.putExtra("type", 3);
                startActivity(intent9);
                break;
            case R.id.ll_geren_main_update_msg_icon:
                Intent intent6 = new Intent(this, PhotoAlbum_Activity.class);
                intent6.putExtra("access_token", access_token);
                intent6.putExtra("bucket", "head");
                intent6.putExtra("cos_type", 0);
                startActivity(intent6);
                break;
            case R.id.rl_geren_main_update_msg_photo:
                Intent intent7 = new Intent(this, GeRen_Update_Msg_PersonPhoto_Activity.class);
                intent7.putExtra("access_token", access_token);
                intent7.putExtra("user_limit", user_limit);
                startActivity(intent7);
                break;
            case R.id.back:
                CommonPopWindow.newBuilder()
                        .setView(R.layout.pop_geren_fans_cancle)
                        .setAnimationStyle(R.style.AnimUp)
                        .setBackgroundDrawable(new BitmapDrawable())
                        .setSize(0, 600)
                        .setViewOnClickListener(this)
                        .setBackgroundDarkEnable(true)
                        .setBackgroundAlpha(0.7f)
                        .build(this)
                        .showAsCenter(v);
                break;
            case R.id.tv_feedback_tijiao:
                SharedPreferences preferences = getSharedPreferences("gd_amapLocation", Context.MODE_PRIVATE);
                JSONObject object = new JSONObject();
                try {
                    object.put("nicename", nickname);
                    object.put("sex", user_limit.getSex());
                    object.put("birthday", time_bron);
                    object.put("height", height);
                    object.put("weigh", weight);
                    object.put("longitude", preferences.getString("longitude", ""));//经度
                    object.put("latitude", preferences.getString("latitude", ""));//纬度
                    object.put("is_face", 1);//纯脸模式 1是 0否
                    object.put("remark", tv_geren_main_update_msg_gxqm.getText().toString().trim());//签名
                    object.put("type", tv_geren_main_msg_tixing.getText().toString().trim());//类型
                    object.put("role", tv_geren_main_update_msg_juese.getText().toString().trim());//角色
                    object.put("face", "");//形象
                    object.put("status", tv_geren_main_gqzk.getText().toString().trim());//情感状态
                    if (style != null){
                        object.put("style", join2(style));//个性特点
                    }
                    if (aim != null){
                        object.put("aim", join2(aim));//目的
                    }
                    if (i_face != null){
                        object.put("i_face", join2(i_face));//喜欢的体型
                    }
                    if (i_style != null){
                        object.put("i_style", join2(i_style));//喜欢的个性特点
                    }
                    object.put("country", tv_geren_main_home.getText().toString().trim());//国家
                    object.put("province", 0);//省份
                    object.put("city", 0);//城市
                    object.put("district", 0);//地区
                    object.put("work", tv_geren_main_msg_work.getText().toString().trim());//工作行业
                    object.put("blood", "");//血型
                    object.put("identity", tv_geren_main_msg_sflb.getText().toString().trim());//身份
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                postTJData(object);
                JSONObject object1 = new JSONObject();
                //直接用选择的文件URI去展示图片
                //如果所选文件不是图片文件，则展示文件图标
                try{
                    object1.put("type", "head");
                    object1.put("path", path);
                    object1.put("p_id", 0);
                    object1.put("sort", 1);
                } catch (Exception e){
                    e.printStackTrace();
                }
                postImgData(object1, access_token);//头像图片获取
                break;
            default:
                break;
        }
    }

    /**
     * 网络请求
     */
    private void postData() {
        JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, RequestConnect.User_Choose_information_Url + access_token + "&sex=" + user_limit.getSex()  + "&client=1", null, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject jsonObject) {
                Log.d("xinyun", jsonObject.toString());
                try {
                    int code = jsonObject.optInt("code");
                    int status = jsonObject.optInt("status");
                    String message = jsonObject.getString("message");
                    if (code == 0) {
                        Gson gson = new Gson();
                        JSONObject info = jsonObject.getJSONObject("info");
                        user_information = gson.fromJson(info.toString(), User_Information.class);
                    } else {
                        ToolUtils.showToast(GeRen_Update_Msg_Activity.this, message);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                ToolUtils.showToast(GeRen_Update_Msg_Activity.this, "网络请求失败，请稍后重试~");
            }
        });
        request.setTag(this);
        VolleyUtil.getQueue(this).add(request);
    }

    /**
     * 网络请求
     */
    private void postTJData(JSONObject object) {
        Log.d("xinyun", object.toString());
        JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, RequestConnect.fill_information_Url + access_token, object, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject jsonObject) {
                Log.d("xinyun", jsonObject.toString());
                try {
                    int code = jsonObject.optInt("code");
                    int status = jsonObject.optInt("status");
                    String message = jsonObject.getString("message");
                    if (code == 0) {
                        Gson gson = new Gson();
                        JSONObject info = jsonObject.getJSONObject("info");
                        ToolUtils.showToast(GeRen_Update_Msg_Activity.this, message);
                        finish();
                    } else {
                        ToolUtils.showToast(GeRen_Update_Msg_Activity.this, message);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                ToolUtils.showToast(GeRen_Update_Msg_Activity.this, "网络请求失败，请稍后重试~");
            }
        });
        request.setTag(this);
        VolleyUtil.getQueue(this).add(request);
    }

    /**
     * 网络请求
     * @param object
     */
    private void postImgData(JSONObject object, String access_token) {
        Log.d("fill_information", object.toString());
        JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, RequestConnect.fill_information_icon_Url + access_token, object, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject jsonObject) {
                Log.d("fill_information", jsonObject.toString());
                try {
                    int code = jsonObject.optInt("code");
                    int status = jsonObject.optInt("status");
                    String message = jsonObject.getString("message");
                    if (code == 0) {
                        Gson gson = new Gson();
                        JSONObject info = jsonObject.getJSONObject("info");
                        String path = info.getString("path");//图片cos访问地址
                        Glide.with(GeRen_Update_Msg_Activity.this).load(path).apply(new RequestOptions()
                                .placeholder(R.mipmap.fill_person_icon).error(R.mipmap.fill_person_icon)
                                .diskCacheStrategy(DiskCacheStrategy.NONE)//关闭Glide的硬盘缓存机制
                        ).into(iv_geren_update_msg_icon);
                    } else {
                        ToolUtils.showToast(GeRen_Update_Msg_Activity.this, message);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                ToolUtils.showToast(GeRen_Update_Msg_Activity.this, "网络请求失败，请稍后重试~");
            }
        });
        request.setTag(this);
        VolleyUtil.getQueue(this).add(request);
    }

    @SuppressLint({"NonConstantResourceId", "SetTextI18n"})
    @Override
    public void getChildView(final PopupWindow mPopupWindow, View view, int mLayoutResId) {
        switch (mLayoutResId) {
            case R.layout.pop_geren_fans_cancle:
                TextView tv_cancle = view.findViewById(R.id.tv_cancle);
                TextView tv_geren_fans_cancle = view.findViewById(R.id.tv_geren_fans_cancle);
                TextView img_guanbi = view.findViewById(R.id.img_guanbi);
                tv_geren_fans_cancle.setText("是否放弃对资料的修改");
                tv_cancle.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mPopupWindow.dismiss();
                        finish();
                    }
                });
                img_guanbi.setText("继续编辑");
                img_guanbi.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mPopupWindow.dismiss();
                    }
                });
                break;
            case R.layout.pop_geren_update_msg_name:
                EditText tv_geren_fans_cancle1 = view.findViewById(R.id.tv_geren_fans_cancle);
                TextView tv_cancle1 = view.findViewById(R.id.tv_cancle);
                TextView img_guanbi1 = view.findViewById(R.id.img_guanbi);
                TextView tv_pop_geren_update_name_count = view.findViewById(R.id.tv_pop_geren_update_name_count);
                tv_cancle1.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mPopupWindow.dismiss();
                    }
                });
                img_guanbi1.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mPopupWindow.dismiss();
                        nickname = tv_geren_fans_cancle1.getText().toString().trim();
                        tv_about_us_code.setText("" + nickname);
                    }
                });
                tv_geren_fans_cancle1.addTextChangedListener(new TextWatcher() {
                    @Override
                    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                    }

                    @Override
                    public void onTextChanged(CharSequence s, int start, int before, int count) {

                    }

                    @Override
                    public void afterTextChanged(Editable s) {
                        tv_pop_geren_update_name_count.setText(s.length() + "/20");
                    }
                });
                break;
            case R.layout.pop_picker_selector_bottom:
                TextView imageBtn = view.findViewById(R.id.img_guanbi);
                TextView tv_cancle2 = view.findViewById(R.id.tv_cancle);
                PickerScrollView addressSelector = view.findViewById(R.id.address);
                PickerScrollView addressSelector2 = view.findViewById(R.id.address2);
                // 设置数据，默认选择第一条
                final List<String> list = new ArrayList();
                if (user_information != null) {
                    for (int i=0; i<user_information.getHeight().size(); i++){
                        list.add(user_information.getHeight().get(i).toString() + "");
                    }
                }
                addressSelector.setData(list);
//                addressSelector.setSelected(0);
                addressSelector.setSelected("160cm");
                height = "160cm";
                //滚动监听
                addressSelector.setOnSelectListener(new PickerScrollView.onSelectListener() {
                    @Override
                    public void onSelect(String pickers) {
                        height = pickers;
                        tv_geren_main_update_msg_height.setVisibility(View.VISIBLE);
                        tv_geren_main_update_msg_height.setText("" + height);
                    }
                });
                // 设置数据，默认选择第一条
                final List<String> list2 = new ArrayList();
                if (user_information != null) {
                    for (int i=0; i<user_information.getWeigh().size(); i++){
                        list2.add(user_information.getWeigh().get(i).toString() + "");
                    }
                }
                addressSelector2.setData(list2);
                addressSelector2.setSelected("60kg");
                weight = "60kg";
                //滚动监听
                addressSelector2.setOnSelectListener(new PickerScrollView.onSelectListener() {
                    @Override
                    public void onSelect(String pickers) {
                        weight = pickers;
                        tv_geren_main_update_msg_height.setVisibility(View.VISIBLE);
                        tv_geren_main_update_msg_height.setText("" + weight);
                    }
                });
                //完成按钮
                imageBtn.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mPopupWindow.dismiss();
                        Log.d("yyyyy", height + weight);
                        tv_geren_main_update_msg_height.setVisibility(View.VISIBLE);
                        tv_geren_main_update_msg_height.setText(height + "/" + weight + "");
                    }
                });
                tv_cancle2.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mPopupWindow.dismiss();
                        height = "";
                        weight = "";
                        tv_geren_main_update_msg_height.setVisibility(View.INVISIBLE);
                        tv_geren_main_update_msg_height.setVisibility(View.INVISIBLE);
                    }
                });
                break;
            default:
                break;
        }
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        initData();
    }

    @Override
    protected void onResume() {
        super.onResume();
        initData();
    }

    @SuppressLint("SetTextI18n")
    private void initData() {
        SharedPreferences preferences = getSharedPreferences("update_message", Context.MODE_PRIVATE);
        SharedPreferences sharedPreferences = getSharedPreferences("photo_path", Context.MODE_PRIVATE);
        path = sharedPreferences.getString("path", "");
        if (! ToolUtils.isEmpty(path)){
            Glide.with(GeRen_Update_Msg_Activity.this).load(path).apply(new RequestOptions()
                    .placeholder(R.mipmap.fill_person_icon).error(R.mipmap.fill_person_icon)
                    .diskCacheStrategy(DiskCacheStrategy.NONE)//关闭Glide的硬盘缓存机制
            ).into(iv_geren_update_msg_icon);
        }
        aim = preferences.getStringSet("aim", null);
        Set<String> aim_name = preferences.getStringSet("aim_name", null);
        String work = preferences.getString("work", "");
        String home = preferences.getString("home", "");
        String face_tixing = preferences.getString("face_tixing", "");
        String role_juese = preferences.getString("role_juese", "");
        String status_name = preferences.getString("status_name", "");
        style = preferences.getStringSet("style", null);
        Set<String> style_name = preferences.getStringSet("style_name", null);
        String identity = preferences.getString("identity", "");
        String gxqm = preferences.getString("gxqm", "");
        i_face = preferences.getStringSet("i_face", null);
        Set<String> i_face_name = preferences.getStringSet("i_face_name", null);
        i_style = preferences.getStringSet("i_style", null);
        Set<String> i_style_name = preferences.getStringSet("i_style_name", null);
        if (i_face_name != null){
            tv_geren_main_msg_tixing.setText("" + join(i_face_name, 3));
            Log.d("xin", "" + i_face);
        } else {
            tv_geren_main_msg_tixing.setText("喜欢他是哪种体型");
        }
        if (i_style_name != null){
            tv_geren_main_msg_like_style.setText("" + join(i_style_name, 3));
            Log.d("xin", "" + i_style);
        } else {
            tv_geren_main_msg_like_style.setText("喜欢他有哪些个性特点");
        }
        if (aim_name == null){
            tv_geren_main_update_msg_aim.setText("选择你的交友目的");
        } else {
            tv_geren_main_update_msg_aim.setText("" + join(aim_name, 3));
            Log.d("xin", "" + aim);
        }
        if (ToolUtils.isEmpty(gxqm)){
            tv_geren_main_update_msg_gxqm.setText("填写你的签名");
        } else {
            tv_geren_main_update_msg_gxqm.setText("" + gxqm);
        }
        if (style_name == null){
            tv_geren_main_msg_style.setText("填写你的个性特点");
        } else {
            tv_geren_main_msg_style.setText("" + join(style_name, 3));
            Log.d("xin", "" + style);
        }
        if (ToolUtils.isEmpty(work)){
            tv_geren_main_msg_work.setText("选择你的工作行业");
        } else {
            tv_geren_main_msg_work.setText("" + work);
        }
        if (ToolUtils.isEmpty(role_juese)){
            tv_geren_main_update_msg_juese.setText("选择你的角色");
        } else {
            tv_geren_main_update_msg_juese.setText("" + role_juese);
        }
        if (ToolUtils.isEmpty(face_tixing)){
            tv_geren_main_update_msg_tixing.setText("选择你的体型");
        } else {
            tv_geren_main_update_msg_tixing.setText("" + face_tixing);
        }
        if (ToolUtils.isEmpty(status_name)){
            tv_geren_main_gqzk.setText("选择你的感情状况");
        } else {
            tv_geren_main_gqzk.setText("" + status_name);
        }
        tv_geren_main_home.setText("" + home);
        if (ToolUtils.isEmpty(identity)){
            tv_geren_main_msg_sflb.setText("选择你的身份类别");
        } else {
            tv_geren_main_msg_sflb.setText("" + identity);
        }
    }

    public static String join(Set<String> stringSet){
        String string = "";
        for(String str :stringSet){
            if("".equals(string)){
                string = str;
            } else {
                string += "、" + str;
            }
        }
        return string;
    }

    public static JSONArray join2(Set<String> stringSet){
        JSONArray array = new JSONArray();
        for(String str :stringSet){
            array.put(str);
        }
        return array;
    }

    /**
     * <h2>Set 集合转字符串</h2>
     * @param stringSet 集合数据
     * @param length 保留集合长度
     * */
    public static String join(Set<String> stringSet, Integer length){
        String strTemp = "";
        Integer setLengthTemp = 1;
        for(String str :stringSet){
            if("".equals(strTemp)){
                strTemp = str;
            } else {
                setLengthTemp ++;
                if(setLengthTemp > length){
                    strTemp += " ...";
                    break;
                }
                strTemp += "、" + str;
            }
        }
        return strTemp;
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
            CommonPopWindow.newBuilder()
                    .setView(R.layout.pop_geren_fans_cancle)
                    .setAnimationStyle(R.style.AnimUp)
                    .setBackgroundDrawable(new BitmapDrawable())
                    .setSize(0, 600)
                    .setViewOnClickListener(this)
                    .setBackgroundDarkEnable(true)
                    .setBackgroundAlpha(0.7f)
                    .build(this)
                    .showAsCenter(view);
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}
